package com.aforce3.trailertracer.optimizations;

import java.util.HashSet;

import javax.vecmath.Point3d;

import com.aforce3.trailertracer.Ray;
import com.aforce3.trailertracer.scenes.Scene;

public class SceneBoundingBox extends BoundingBox
{
	Scene scene;
	
	public SceneBoundingBox(Point3d upperLeftBack, Point3d lowerRightFront, Scene scene)
	{
		super(upperLeftBack, lowerRightFront);
		this.scene = scene;
	}
	
	public SceneBoundingBox(BoundingBox b, Scene scene)
	{
		super(b.upperLeftBack, b.lowerRightFront);
		this.scene = scene;
	}
	
	public void setScene(Scene s){
		scene = s;
	}
	
	public Intersection getIntersection(Ray ray, HashSet<Scene> child, boolean lights)
	{
		if(child.contains(scene)) return null;
		
		child.add(scene);
		
		if(!lights && scene.isLight()) return null;
		//TODO: Check to see if the ray hits this box; if not, return null
		
		Point3d point = scene.calculateIntersect(ray);
		
		if(point == null) return null;
		
		return new Intersection(scene, point);
	}
}

